<template>
  <div>
    <el-table
      :data="orderData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="ID"
        width="100">
      </el-table-column>
      <el-table-column
        prop="totalAmount"
        label="总金额"
        width="100">
      </el-table-column>
      <el-table-column
        prop="createdAt"
        label="下单时间"
        width="400">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
        <el-button
          size="mini"
          @click="detailed(scope.$index, scope.row)">详细
        </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageable.pageNumber"
        :page-sizes="[10, 20, 40]"
        :page-size="pageable.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalElements">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import itemService from "../global/service/itemService";

export default {
  name: "OrderList",
  data() {
    return {
      orderData: [],
      pageable: {
        pageNumber: 1,
        pageSize: 10
      },
      totalElements: 0,
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    async getOrderList() {
      let res = await itemService.getOrderList(
        {
          page: this.pageable.pageNumber - 1,
          size: this.pageable.pageSize,
        }
      );
      this.orderData = res.content
      this.totalElements = res.totalElements
    },
    detailed(index, row) {
      let id = row.id;
      this.$router.push({
        name: 'OrderDetails',
        query: {
          id: id,
        }
      })
    },
    handleSizeChange(val) {
      this.pageable.pageSize = val;
      this.getOrderList()
    },
    handleCurrentChange(val) {
      this.$route.query.page = val;
      this.getOrderList()
    },
  }
}
</script>

<style scoped>

</style>
